﻿
Imports System.Data.OleDb
Imports System.Xml
Imports System.ServiceModel.Syndication



Public Class RSS
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.ContentType = "application/rss+xml"

        Dim myFeed As New SyndicationFeed

        myFeed.Title = TextSyndicationContent.CreatePlaintextContent("shassan6 Location")
        myFeed.Description = TextSyndicationContent.CreatePlaintextContent _
        ("The Current most recent article added to the Halal Dining in London Town website")
        myFeed.Links.Add(SyndicationLink.CreateSelfLink _
                         (New Uri(okURL("location.apsx"))))
        myFeed.Language = "en-us"

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Outletsdb").ConnectionString)
        oleDbConn.Open()
        Dim cmdQuery As String = "SELECT TOP 5 * from Location"
        Dim dbcomm = New OleDbCommand(cmdQuery, oleDbConn)
        Dim dbread = dbcomm.ExecuteReader()

        Dim myItems As New List(Of SyndicationItem)
        While dbread.Read()
            Dim sItem As New SyndicationItem
            sItem.Title = makeRssTxt(dbread("Area"))
            sItem.Summary = makeRssTxt(dbread("Cuisine") & dbread("Comments"))
            sItem.Links.Add(mkRssLink(dbread("Comments")))
            myItems.Add(sItem)
        End While

        myFeed.Items = myItems

        Dim feedwriter As XmlWriter = XmlWriter.Create(Response.OutputStream)
        Dim rssFormatter = New Rss20FeedFormatter(myFeed)
        rssFormatter.WriteTo(feedwriter)
        feedwriter.Close()


    End Sub


    Private Function mkRssLink(ByVal someLocation As String) As SyndicationLink
        Return SyndicationLink.CreateAlternateLink(New Uri(someLocation))
    End Function

    Private Function makeRssTxt(ByVal someString As String) As TextSyndicationContent
        Return TextSyndicationContent.CreatePlaintextContent(someString)
    End Function

    Private Function okURL(ByVal urlStr As String)
        Return Request.Url.GetLeftPart(UriPartial.Authority) & ResolveUrl(urlStr)
    End Function






End Class